home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 June: Reference Library / Dev.CD Jun 96 RL / Dev.CD Jun 96 RL.toast / Technical Documentation / develop / develop Issue 24 / develop Issue 24 code / Scriptable Database 1.0a15 / Base / Object.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-19  |  7.7 KB  |  264 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        Object.h
  3.  
  4.     Contains:    *** put contents here ***
  5.  
  6.     Written by:    Bruce Horn, Steve Capps, Larry Kenyon, John Meier, scott douglass, Darin Adler,
  7.                 Paul Mercer, Bryan Stearns, Dave Owens
  8.                 
  9.                 Andy Nicholas
  10.  
  11.     Copyright:    © 1988-1995 by Apple Computer, Inc., all rights reserved.
  12.  
  13.          <5>     6/23/95    ga        
  14. */
  15.  
  16. #ifndef Object_h
  17. #define Object_h
  18.  
  19. // #include "ClassIDs.h"
  20.  
  21. #ifndef REZ
  22.  
  23. #include "Debug.h"
  24.  
  25. //
  26. // Types.h is needed for definition of "Boolean"
  27. //
  28. #include <Types.h>
  29.  
  30. class TPropertyDescription;
  31.  
  32. //========================================================================================
  33. // CLASS TClassPropertyInfo
  34. //========================================================================================
  35.  
  36. class TClassPropertyInfo
  37.     {
  38. public:
  39.     Boolean                                PropertyExists(UInt32 propertyName) const;
  40.     const TPropertyDescription*            DescriptionOfProperty(UInt32 propertyName) const;
  41.     SInt32                                NumberOfProperties() const;
  42.     const TPropertyDescription*            DescriptionOfNthProperty(SInt32 propertyNumber) const;
  43.  
  44. public:
  45.     SInt32                                fPropertyCount;
  46.     TPropertyDescription*                fArrayOfPropertyIdentifiers;
  47.     };
  48.  
  49. //========================================================================================
  50. // CLASS TClassData
  51. //========================================================================================
  52.  
  53. class TClassData
  54.     {
  55. public:
  56. #ifdef DEBUG
  57.     char*                        fClassName;                        // In debug builds, the name of this class
  58. #endif
  59.     UInt32                        fObjectClass;                    // The object class is the Object-Support-Library class for this class
  60.     UInt32                        fClassID;                        // The class ID is used to partition the resource-ID/property ID space
  61.     UInt32                        fObjectSize;                    // The size of the class that this class data describes
  62.     TClassData*                    fSuperClass;                    // A pointer to the superclass' class data
  63.     TClassPropertyInfo            fClassPropertyInfo;                // A table that describes the properties for this class
  64.     
  65. public:
  66.     UInt32                        ObjectClass() const                { return fObjectClass; }
  67.     UInt32                        ClassID() const                    { return fClassID; }
  68.     UInt32                        ObjectSize() const                { return fObjectSize; }
  69.  
  70.     const TClassData*            SuperClass() const                { return fSuperClass; }
  71.     const TClassPropertyInfo&    ClassPropertyInfo() const        { return fClassPropertyInfo; }
  72.     };
  73.  
  74.  
  75. //
  76. // Backwards compatability (don't use these)
  77. //
  78. #if 0
  79.  
  80. #define DECLAREOBJECT(className)                            \
  81.                 static        TClassData  fClassData;            \
  82.                 virtual     const TClassData* ClassData() const
  83.  
  84. #ifdef DEBUG
  85.  
  86. #define IMPLEMENTOBJECT(className, classID, signature, superclass)                \
  87.         const TClassData* className::ClassData() const { return &fClassData; }         \
  88.         TClassData className::fClassData = {#className, 0, classID, sizeof(className), &superclass::fClassData, {0, nil} }
  89.  
  90. #else
  91.  
  92. #define IMPLEMENTOBJECT(className, classID, signature, superclass)                \
  93.         const TClassData* className::ClassData() const { return &fClassData; }         \
  94.         TClassData className::fClassData = {0, classID, sizeof(className), &superclass::fClassData, {0, nil} }
  95.  
  96. #endif
  97. #endif
  98.  
  99. //
  100. // Classes that do not define additonal properties use these
  101. // versions of the defines to save a little memory
  102. //
  103. #define DeclareSmallClassData(className, superclass)                                                                \
  104.                 static        TClassData          fClassData;                                                            \
  105.                 typedef        superclass            Inherited;                                                            \
  106.                 virtual     const TClassData*    ClassData() const
  107.  
  108. #ifdef DEBUG
  109.  
  110. #define ImplementSmallClassData(className, classID)                                                                    \
  111.         const TClassData* className::ClassData() const { return &fClassData; }         \
  112.         TClassData className::fClassData = {#className, 0, classID, sizeof(className), &className::Inherited::fClassData, {0, nil} }
  113.  
  114. #else
  115.  
  116. #define ImplementSmallClassData(className, classID)                                                                    \
  117.         const TClassData* className::ClassData() const { return &fClassData; }         \
  118.         TClassData className::fClassData = {0, classID, sizeof(className), &className::Inherited::fClassData, {0, nil} }
  119.  
  120. #endif
  121.  
  122.  
  123. class TObject;
  124. class TBehavior;
  125.     
  126. //========================================================================================
  127. // CLASS TCanReceiveDeleteNotification
  128. //
  129. // See comment with RegisterForDeleteNotification, below
  130. //========================================================================================
  131.  
  132. class TCanReceiveDeleteNotification
  133.     {
  134. public:
  135.     virtual void            ItemBeingDeleted(const TObject*) = 0;
  136.     };
  137.  
  138. //
  139. // Use with RegisterForDeleteNotification
  140. //
  141. enum
  142.     {
  143.     kUnregisterForDeleteNotification = 0,
  144.     kRegisterForDeleteNotification
  145.     };
  146.     
  147. //========================================================================================
  148. // CLASS TObject
  149. //========================================================================================
  150.  
  151. class TObject
  152.     {
  153. #ifdef DEBUG
  154. private:
  155.         //
  156.         // This data is redundant, because it is available by way of
  157.         // the virtual method ClassData().  We include it here in debug
  158.         // builds so that we can find this information with greater
  159.         // ease if we dump memory.
  160.         //
  161.         SInt32                        fSignature;
  162.         const TClassData*            fClassDataPtr;
  163.         
  164.         void                        SetupObjectDebugInfo();
  165. #endif
  166.  
  167. public:
  168.         //
  169.         // Most classes will use the DeclareClassData macro instead of
  170.         // explicitly declaring their class data.  TObject cannot use
  171.         // the macros, though, as it has no superclass.
  172.         //
  173.         static TClassData              fClassData;
  174.         virtual const TClassData*    ClassData() const;
  175.         
  176. #ifdef DEBUG
  177.                                     TObject() : fSignature(0), fClassDataPtr(nil) {}
  178. #endif
  179.         virtual                        ~TObject();
  180.  
  181.         //
  182.         // TObjects may be cloned; override 'CloneOwnedObjects'
  183.         // and clone any memory blocks owned by the derived class
  184.         //
  185.                 TObject*            Clone();
  186.         virtual void                CloneOwnedObjects();
  187.         
  188.         //
  189.         // TObjects have class data that may be inspected
  190.         //
  191.                 SInt32                 ClassID() const;
  192.                 UInt32                ObjectSize() const;
  193.                 Boolean                DerivedFrom(SInt32 cast) const;
  194.         
  195.         //
  196.         // If SortOrder and Key are overridden, then a list of
  197.         // TObjects may be sorted
  198.         //
  199.         virtual    Boolean                SortOrder(const TObject*, void*) const;
  200.         virtual SInt32                Key() const;
  201.  
  202.         //
  203.         // Call RegisterForDeleteNotification if you (a TObject-derived class)
  204.         // would like to be informed when this object is deleted.  RegisterForDeleteNotification
  205.         // will return 'true' if this object is capable of this notification.
  206.         //
  207.         // ItemBeingDeleted will be called on the object that was registered when
  208.         // this item is deleted.
  209.         //
  210.         // For example:
  211.         //
  212.         //        TCanReceiveDeleteNotification* object1;
  213.         //        TObject* object2;
  214.         //
  215.         //        //
  216.         //        // Tell object2 that object1 would like to be notified
  217.         //        // when object2 is deleted
  218.         //        //
  219.         //        object2->RegisterForDeleteNotification(object1);
  220.         //
  221.         //        delete object2;
  222.         //
  223.         //            causes: object1->ItemBeingDeleted(object2);
  224.         //
  225.         virtual Boolean                RegisterForDeleteNotification(TCanReceiveDeleteNotification*, Boolean shouldRegister);
  226.  
  227.         //
  228.         // Behavior support:
  229.         //
  230.         // It is not possible to add a behavior to a plain TObject because
  231.         // there is no storage for it.  Subclasses may override FirstBehavior and
  232.         // SetFirstBehavior in order to allow behaviors to be added to them.
  233.         //
  234.         virtual TBehavior*            FirstBehavior() const;
  235.         virtual void                SetFirstBehavior(TBehavior* firstBehavior);
  236.         
  237.         TBehavior*                    FirstBehaviorOfClass(SInt32 classID) const;
  238.  
  239.         void                        AddBehavior(TBehavior* behavior);
  240.         void                        RemoveBehavior(TBehavior* behavior);
  241.  
  242.         //
  243.         // A few of our friends
  244.         //
  245. friend            Boolean                operator==(const TObject&, const TObject&);    // compares Key()s
  246. friend            Boolean                operator<(const TObject&, const TObject&);    // compares Key()s
  247.     };
  248.     
  249. #ifndef DEBUG
  250.  
  251. //
  252. // These methods are not inlined in debug builds so that 
  253. // they can set up the debugging information for the object when they
  254. // are first called.
  255. //
  256. inline SInt32 TObject::ClassID() const { return ClassData()->ClassID(); }
  257. inline UInt32 TObject::ObjectSize() const { return ClassData()->ObjectSize(); }
  258.  
  259. #endif
  260.  
  261. #endif // REZ
  262. #endif // Object_h
  263.  
  264.